package com.nutricia.core.service.convertor;

import com.nutricia.common.dal.persistant.SystemUser;
import com.nutricia.common.dal.persistant.SystemUserOther;
import com.nutricia.core.model.domain.SystemUserDO;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 系统用户对象转换器
 *
 * @author: huangsheng
 * @date: 2017/10/20
 */
public class SystemUserServiceConvertor {

    /**
     * 将 SystemUserOther 转换为 SystemUserDO
     *
     * @author: huangsheng
     * @date: 2017/10/20 下午2:00
     */
    public static SystemUserDO systemUserOtherConvertToSystemUserDO(SystemUserOther systemUser) {
        if (null == systemUser) {
            return null;
        }
        SystemUserDO systemUserDO = new SystemUserDO();
        systemUserDO.setUserName(systemUser.getUserName());
        systemUserDO.setUserLoginName(systemUser.getUserLoginName());
        systemUserDO.setCreateId(systemUser.getCreateId());
        systemUserDO.setCreateTime(systemUser.getCreateTime());
        systemUserDO.setCurrentLoginIp(systemUser.getCurrentLoginIp());
        systemUserDO.setCurrentLoginTime(systemUser.getCurrentLoginTime());
        systemUserDO.setId(systemUser.getId());
        systemUserDO.setLastLoginIp(systemUser.getLastLoginIp());
        systemUserDO.setLastLoginTime(systemUser.getLastLoginTime());
        systemUserDO.setUserState(systemUser.getUserState());
        systemUserDO.setCreateName(systemUser.getCreateName());
        systemUserDO.setModifyName(systemUser.getModifyName());
        systemUserDO.setModifyTime(systemUser.getModifyTime());
        systemUserDO.setUserMail(systemUser.getUserMail());
        return systemUserDO;
    }

    /**
     * 将SystemUsers转换为SystemUserDOs
     *
     * @author: huangsheng
     * @date: 2017/10/20 下午2:00
     */
    public static List<SystemUserDO> convertToDOs(List<SystemUserOther> systemUsers) {
        List<SystemUserDO> systemUserDOS = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(systemUsers)) {
            systemUsers.forEach(systemUser -> {
                systemUserDOS.add(SystemUserServiceConvertor.systemUserOtherConvertToSystemUserDO(systemUser));
            });
            return systemUserDOS;
        }
        return null;
    }

    /**
     * 将SystemUser 转换 为SystemUserDO
     *
     * @author: huangsheng
     * @date: 2017/10/20 下午2:00
     */
    public static SystemUserDO systemUserConvertToSystemUserDO(SystemUser systemUser) {
        if (null == systemUser) {
            return null;
        }
        SystemUserDO systemUserDO = new SystemUserDO();
        systemUserDO.setUserName(systemUser.getUserName());
        systemUserDO.setUserLoginName(systemUser.getUserLoginName());
        systemUserDO.setCreateId(systemUser.getCreateId());
        systemUserDO.setCreateTime(systemUser.getCreateTime());
        systemUserDO.setCurrentLoginIp(systemUser.getCurrentLoginIp());
        systemUserDO.setCurrentLoginTime(systemUser.getCurrentLoginTime());
        systemUserDO.setId(systemUser.getId());
        systemUserDO.setLastLoginIp(systemUser.getLastLoginIp());
        systemUserDO.setLastLoginTime(systemUser.getLastLoginTime());
        systemUserDO.setUserState(systemUser.getUserState());
        systemUserDO.setModifyTime(systemUser.getModifyTime());
        systemUserDO.setModifyId(systemUser.getModifyId());
        systemUserDO.setUserMail(systemUser.getUserMail());
        return systemUserDO;
    }

}
